<template>
  <view class="shop-status">
    <uni-list>
      <uni-list-item title="暂停营业" note="打开开关后顾客无法下单" :show-arrow="false">
        <template v-slot:right>
          <switch :checked="checked" :disabled="disabled" @change="switchChange" />
        </template>
      </uni-list-item>
    </uni-list>
  </view>
</template>

<script>
import { mapGetters, mapActions } from "vuex";
export default {
  data() {
    return {
      checked: false
    };
  },
  computed: {
    ...mapGetters({
      activeShop: "activeShop"
    }),
    businessStatus() {
      return this.activeShop.businessStatus;
    },
    // 是否不可用
    disabled() {
      return this.activeShop.businessStatus == 2;
    }
  },
  onLoad() {
    // 是否关闭 当为1时，打开开关，店铺暂停营业
    if (this.businessStatus == 1) this.checked = true;
  },
  methods: {
    ...mapActions({
      putShop: "putShop"
    }),
    init() {},
    async switchChange(e) {
      let params = { businessStatus: 1, shopName: this.activeShop.shopName };
      if (e.detail.value) {
        params.businessStatus = 1;
      } else {
        params.businessStatus = 0;
      }
      let res = this.putShop({ params });
      if (!res.code) {
        this.checked = !this.checked;
      } else {
        this.checked = this.checked;
      }
    }
  }
};
</script>

<style lang="scss">
</style>
